Formatter - Sample Code

Formatter - Sample Code

LatitudeFormatter Example for Custom Formatter Plugins

This example demonstrates a formatter plugin for Oracle Web Determinations.  For more general information on constructing and debugging plugins, see the topic, Create a Plugin

The example custom formatter defers to the default formatter for all values except for attribute values where a Number attribute has a custom property IsLatitude set to "True".

For these, it formats and parses numbers as Latitude values eg. 28°32'45.63"S

The example includes a re-usable abstract class, PassthroughFormatter, which delegates all formatting to the default formatter, allowing your custom formatter to concentrate on special cases.

To construct the example:

Test that the LatitudeFormatterExample rulebase is working correctly.

  1. Copy the uncompiled LatitudeFormatterExample.zip rulebase source from examples\rulebases\source in either the Java or .NET runtime zip file, to a location on your machine where it can be unzipped ready for use with Oracle Policy Modeling.
  2. In Oracle Policy Modeling, choose Build->Build and Debug..., With screens.
  3. An interview should open, in which you can determine if an applicant is eligible for the imaginary polar-resident benefits by entering a number, such as "-30" or "4000"
  4. Note that at this point our web application is accepting these bad latitude values!
  5. After determining your eligibility, click on, "Why?" You should get a display like this, showing your input:


 

You should now have a functioning rulebase. If your rulebase is not working correctly so far, you should fix any problems before proceeding to the customization steps.

Build a formatter plugin

The next task is to build a plugin. Our plugin has two classes:

Copy the LatitudeFormatter.jar file or the LatitudeFormatter.dll file (located in examples\web-determinations\custom-formatter in either the Java or .NET runtime zip) to your rulebase's plugins directory, where Oracle Web Determinations can find it. If your rulebase is at <...>\LatitudeExample, the correct directory for your plugin is <...>\LatitudeExample\Release\web-determinations\WEB-INF\classes\plugins. If the Release directory does not exist, Build and Debug your rulebase once to create it; your plugin should now be loading, but it won't be doing anything visible yet.

Customize the rulebase to use the plugin

Now we want to invoke our plugin to format our rulebase's "the latitude of the person's primary residence" attribute as a latitude. The plugin is looking for a custom property, "IsLatitude" so we need to create that property and set it on the special attribute.

Note: Although this customization has already been done for you in the provided sample rulebase (LatitudeFormatterExample.zip found in examples\rulebases\compiled), the following is a description of how to do it in general:

  1. In Oracle Policy Modeling, choose File->Project Properties..., add a Boolean custom property called "IsLatitude", and click OK:



  2. Right-click the "Properties" folder, and choose "Add New Properties File". Call it "properties"
  3. Open the properties file, right-click inside the empty "Attributes" section for the global entity, and choose, "Generate Public Names..."
  4. Make sure the checkbox is ticked for the attribute, "the latitude of the person's primary residence"
  5. The attribute should now show up in the view. Double-click it to edit its properties:



  6. Click the "Custom Properties" tab at the bottom of the dialog, and add a value of "True":




  7. Click OK, save, and build and debug again. Your custom formatter should now be working! On the latitude question, you may enter a number as before, or you may enter a latitude value such as: 30°12'13"S (Because the ° character can be hard to type, the formatter also accepts a space as in 30 12'13"S )
  8. Whether you enter a decimal number or a properly-formatted latitude, the custom formatter will reject values beyond the north or south pole, and show a properly-formatted latitude on the decision report screen:

Source Code

To view the source code for the LatitudeFormatter sample, refer to examples\web-determinations\custom-formatter in either the Java or .NET runtime zip file.